<template>
 <div>
   <!--    面包屑导航栏-->
   <el-breadcrumb separator="/">
     <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
     <el-breadcrumb-item>商品管理</el-breadcrumb-item>
     <el-breadcrumb-item>商品列表</el-breadcrumb-item>
   </el-breadcrumb>
<!--   卡片区域-->
   <el-card class="box-card">
<!--     表格区域-->
      <el-button type="primary">添加商品</el-button>
     <el-table :data="goodsList" style="width: 100%" stripe border>
       <el-table-column label="#" type="index">
       </el-table-column>
       <el-table-column prop="goods_name"
           label="商品名称">
       </el-table-column>
       <el-table-column prop="goods_price" label="商品价格(元)" width="120px" align="center">
       </el-table-column>
       <el-table-column prop="goods_weight" label="商品重量" width="80px" align="center">
       </el-table-column>
       <el-table-column prop="add_time" label="创建日期" width="120px" align="center">
       </el-table-column>
       <el-table-column label="操作" width="130px" align="center">
         <template #default="scope">
           <el-button type="primary" icon="el-icon-edit" size="mini"></el-button>
           <el-button type="danger" icon="el-icon-delete" size="mini"></el-button>
         </template>
       </el-table-column>
     </el-table>
   </el-card>
   <el-pagination   :current-page="goodsParams.pagenum"  :page-size="goodsParams.pagesize"
                    :page-sizes="[2, 5, 8, 10]" :total="total" layout="total, sizes, prev, pager, next, jumper"
                    @size-change="handleSizeChange" @current-change="handleCurrentChange">
   </el-pagination>
  </div>
</template>

<script>
import {request} from "../../../network/axios";

export default {
  name: "goods",
  created() {
    this.getGoodData()
  },
  data(){
    return{
        goodsParams:{
          query:'',
          pagenum:1,
          pagesize:8
        },
      total:20,
      goodsList:[]
    }
  },
  methods:{
    //获取商品列表数据
    getGoodData(){
      request({
        url: `goods`,
        method:'get',
        params:this.goodsParams
      }).then(res=>{
        this.goodsList = res.data.data.goods
        this.total = res.data.data.total
        console.log(res.data.data.goods);
      })
    },
    handleSizeChange(newSize){
      this.goodsParams.pagesize = newSize
      this.getGoodData()
    },
    handleCurrentChange(newPage){
      this.goodsParams.pagenum = newPage
      this.getGoodData()
    }
  },

}
</script>

<style scoped src="../../../assets/css/goods/goods.css">

</style>